package collection;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author DBX
 * @effect 集合只能存放引用类型元素，并且保存的是元素的引用
 * @date 2021/09/02/17:18
 */
public class CollectionDemo2 {
    public static void main(String[] args) {
        Collection c = new ArrayList();

        Point p = new Point(1,2);
        c.add(p);

//        System.out.println("p:"+p);
//        System.out.println("p:"+c);
//        p.setX(2);
//        System.out.println("p:"+p);
//        System.out.println("p:"+c);

        String s ="hello";
        int a =1;
        c.add(p);

        test(s,a,p,c);
        System.out.println(s);
        System.out.println(a);
        System.out.println(p);
        System.out.println(c);
    }
    public static void test(String s,int a ,Point p,Collection c){
        a++;
        s = s+"world";
        p.setX(3);
        p = new Point(4,5);
        c.clear();
        c.add(p);
        c = new ArrayList();
        p.setX(7);
        c.add(p);
    }
}
